package com.books.mapper.book;/*
 *@Auther Zhourui
 *@data 2021/9/29  20:01
 *@Email 1605576647@qq.com
 */

import com.books.model.entity.book.Books;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface BookMapper{
    @Select("select * from books where bk_id=#{id}")
    Books getById(Integer id);

    @Select("select * from books")
    List<Books> findAll();

    //多条件参数
    List<Books> getAll(@Param("title") String title, @Param("categoryId") Integer categoryId);

    List<Books> getAllTitle(@Param("title") String title);

    /**
     * 根据出版社模糊查询书籍
     * @param compay
     * @return
     */
    @Select("select * from books where compay like '%${compay}%'")
    List<Books> findByBookCompay(String compay);

    /**
     * 根据标题模糊查询书籍
     * @param title
     * @return
     */
    @Select("select * from books where title like '%${title}%'")
    List<Books> findByBookName(String title);

    /**
     * 根据作者模糊查询
     * @param author
     * @return
     */
    @Select("select * from books where author like '%${author}%'")
    List<Books> findByAuthor(String author);

    /**
     * 根据类别查询
     * @param categoryId
     * @return
     */
    @Select("select * from books where category_id=#{categoryId}")
    List<Books> findByBookType(Integer categoryId);

    @Delete("delete from books where bk_id=#{bkId}")
    void delByBkId(Integer bkId);

    @Update("update books set price=#{price} where bk_id=#{bkId}")
    void updateBook(Integer bkId,Double price);

    @Update("update books set stock=#{stock} where bk_id=#{bkId}")
    void updateBookStock(Integer bkId,Integer stock);

    @Insert("insert into books values(null,#{title},#{price},#{author},#{date},#{compay},#{pictureUrl},#{detail},#{categoryId},#{stock})")
    void addBook(Books books);
}
